IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MFBreakFileNameWithPathForFileName]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
BEGIN
     DROP FUNCTION [dbo].[MFBreakFileNameWithPathForFileName]
END
GO

CREATE FUNCTION [dbo].[MFBreakFileNameWithPathForFileName](@FileNameWithPath [nvarchar](4000))
RETURNS [nvarchar](4000) WITH EXECUTE AS CALLER
AS 
EXTERNAL NAME [FileManipulationSQLCLRExternal].[FileManipulationSQLCLRExternal.UserDefinedFunctions].[MFBreakFileNameWithPathForFileName]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MFBreakFileNameWithPathForFilePath]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
BEGIN
     DROP FUNCTION [dbo].[MFBreakFileNameWithPathForFilePath]
END
GO

CREATE FUNCTION [dbo].[MFBreakFileNameWithPathForFilePath](@FileNameWithPath [nvarchar](4000))
RETURNS [nvarchar](4000) WITH EXECUTE AS CALLER
AS 
EXTERNAL NAME [FileManipulationSQLCLRExternal].[FileManipulationSQLCLRExternal.UserDefinedFunctions].[MFBreakFileNameWithPathForFilePath]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MFFileExistsCheck]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
BEGIN
     DROP FUNCTION [dbo].[MFFileExistsCheck]
END
GO

CREATE FUNCTION [dbo].[MFFileExistsCheck](@FilePath [nvarchar](4000), @FileName [nvarchar](4000))
RETURNS [tinyint] WITH EXECUTE AS CALLER
AS 
EXTERNAL NAME [FileManipulationSQLCLRExternal].[FileManipulationSQLCLRExternal.UserDefinedFunctions].[MFFileExistsCheck]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MFFolderExistsCheck]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
BEGIN
     DROP FUNCTION [dbo].[MFFolderExistsCheck]
END
GO

CREATE FUNCTION [dbo].[MFFolderExistsCheck](@FullDirectoryPath [nvarchar](4000))
RETURNS [tinyint] WITH EXECUTE AS CALLER
AS 
EXTERNAL NAME [FileManipulationSQLCLRExternal].[FileManipulationSQLCLRExternal.UserDefinedFunctions].[MFFolderExistsCheck]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MFGetFileImage]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
BEGIN
     DROP FUNCTION [dbo].[MFGetFileImage]
END
GO

CREATE FUNCTION [dbo].[MFGetFileImage](@FilePath [nvarchar](4000), @FileName [nvarchar](4000))
RETURNS [varbinary](max) WITH EXECUTE AS CALLER
AS 
EXTERNAL NAME [FileManipulationSQLCLRExternal].[FileManipulationSQLCLRExternal.UserDefinedFunctions].[MFGetFileImage]
GO
